/*
 * @Author: TT-hzy 
 * @Date: 2024-06-29 18:18:28
 * @LastEditors: TT-hzy 
 * @LastEditTime: 2024-07-05 10:16:25
 * @Description: 
 */

import { Service } from "egg";


import * as crypto from 'crypto';






class CommonService extends Service {
  public async getUserInfoByPk(id: number) {

    const user = await this.ctx.model.User.findByPk(id);
    return user;

  }

  public async getUserInfoByName(name: string) {

    const user = await this.ctx.model.User.findOne({
      where: {
        name,
      }
    });
    return user;
  }

  public async getUserInfoByNameAndPassword(name: string, password: string) {
    const user = await this.ctx.model.User.findOne({
      where: {
        name,
        password,
      }
    });
    console.log(user);
    return user;
  }

  public getMd5Data(data: string) {
    return crypto.createHash('md5').update(data).digest("hex");
  }
}


export default CommonService;